/*
XPT2046 / AD7843 Touch Screen Driver for PIC32MX795F512L
Copyright (C) 2012 Craig Dawson, Aaron Mohtar, Craig Peacock

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "HardwareProfile.h"
#include "StaticText.h"

#define ENABLE 1
#define DISABLE 0

#define TMR3FREQ 10
#define TMR3DELAY 100/TMR3FREQ

#define touchScrInterrupt(command)  IFS0bits.INT4IF = 0;    IEC0bits.INT4IE = command;
#define tmr3Interrupt(command)      IFS0bits.T3IF = 0;      IEC0bits.T3IE = command;

// XPT2046 functions
void touchScrInit(unsigned char EnableInterrupt);
unsigned int touchScrSPICommand(unsigned int command);
void touchScrCalibrate();
unsigned char touchScrGetCord(unsigned int * scaled_x, unsigned int * scaled_y, int * pressure);

/* Control byte definitions:
   MSb                                                     LSb
-----------------------------------------------------------------
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
-----------------------------------------------------------------
| Start | A2    | A1    | A0    | Mode  | SER   | PD1   | PD0   |
-----------------------------------------------------------------

 Start      1 = Start Bit
 A[2:0]     001 = X+
            010 = IN3
            101 = Y+
            110 = IN4
 Mode       0 = 12 bit resolution, 1 = 8 bit resolution
 SER        1 = Single Ended
            0 = Differential
 PD[1:0]    00 = Power down between conversions, PENIRQ enabled
            01 = Power down between conversions, PENIRQ disabled
            10 = Always powered up, PENIRQ enabled
            11 = Always powered up, PENIRQ disabled
 */

#define TS_SAMP_X  0b11010100
#define TS_SAMP_Y  0b10010100
#define TS_SAMP_Z1  0b10110100
#define TS_SAMP_Z2  0b11000100

